﻿using System;
using System.Data;
using System.Linq;
using System.Net;
using System.Text;
using YXShop.Common.TaoBaoAPI;

namespace YXShop.Web.admin.product
{
    public partial class product_taobaoimport : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                YXShop.Common.PromptInfo.Popedom("001006006", "对不起，您没有淘宝数据导入的权限");
                InitWebControl();
                p_bottom.Visible = false;
                pl_news.Visible = true;
            }
        }
        /// <summary>
        /// 获取商品列表事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Button1_Click(object sender, EventArgs e)
        {

            string message = "";
            if (tb_appkey.Text == string.Empty || tb_appkey.Text.Trim() == "")
            {
                message = "非空，请输入淘宝appkey。";
            }
            else
            {
                if (tb_appsecret.Text == string.Empty || tb_appsecret.Text.Trim() == "")
                {
                    message = "非空，请输入淘宝appsecret。";
                }
            }
            if (message == "" || message == string.Empty)
            {
                if (GetList(tb_appkey.Text, tb_appsecret.Text, 1) > 0)
                {
                    pl_news.Visible = false;
                    p_bottom.Visible = true;
                }
                else
                {
                    this.ltlMsg.Text = "淘宝商品列表中没有商品或者appkey和appsecret不是有效的";
                    this.pnlMsg.Visible = true;
                    this.pnlMsg.CssClass = "actionErr";
                }
            }
            else
            {
                this.ltlMsg.Text = message;
                this.pnlMsg.Visible = true;
                this.pnlMsg.CssClass = "actionErr";
            }
        }

        #region 搜索设置
        private void InitWebControl()
        {
            YXShop.Common.SysParameter sp = new YXShop.Common.SysParameter();
            this.txtArea.Attributes.Add("readonly", "readonly");
            this.txtArea.Attributes.Add("onclick", "selectFile('Area',new Array(" + this.w_l_pro_Area.ClientID + "," + this.txtArea.ClientID + "),310,450,'" + sp.DummyPaht + "');");
            this.txtProductClass.Attributes.Add("readonly", "readonly");
            this.txtProductClass.Attributes.Add("onclick", "selectFile('Productclass',new Array(" + this.w_d_pro_CID.ClientID + "," + this.txtProductClass.ClientID + "),310,450,'" + sp.DummyPaht + "');");
        }
        #endregion
 
        /// <summary>
        /// 根据IID获取选中的商品信息
        /// </summary>
        /// <param name="str">IID</param>
        /// <returns></returns>
        protected DataTable GetTable(string str)
        {
            string[] idds = str.Split(',');

            DataTable dt = (DataTable)ViewState["PC"];
            DataTable dtnew = dt.Clone();

            foreach (DataRow dr in dt.Rows)
            {
                if (idds.Contains(dr["iid"]))
                {
                    dtnew.ImportRow(dr);
                }
            }

            return dtnew;



        }
        /// <summary>
        ///  列表
        /// </summary>
        /// <returns></returns>
        protected int GetList(string appkey, string appsecret,int pageindex)
        {
            YXShop.Common.SysParameter sp = new YXShop.Common.SysParameter();
            YXShop.Common.TaoBaoAPI.TaobaoCommon tc = new YXShop.Common.TaoBaoAPI.TaobaoCommon();
            ChangeHope.WebPage.Table table = new ChangeHope.WebPage.Table(); ;//获取淘宝数据
            long count =0;
            DataTable dt =tc.GetTable(appkey, appsecret,pageindex,ref count);
            ViewState["PC"] = dt;
            //第一步先添加表头
            table.AddHeadCol("10%", "<input type=\"checkbox\" id=\"chkAll\" onclick=\"CheckAll(this.form)\" alt=\"全选/取消\" />选择");
            //table.AddHeadCol("20%", "所属分类");
            table.AddHeadCol("25%", "商品名称");
            table.AddHeadCol("10%", "商城价");
            table.AddHeadCol("10%", "库存");
            table.AddHeadCol("25%", "状态");
            table.AddHeadCol("20%", "操作");
            table.AddRow();
            //添加表的内容
            if (dt.Rows.Count > 0&&dt!=null)
            {
                foreach (DataRow dr in dt.Rows)
                {
                    table.AddCol("<input ID=\"cBox\" name=\"cBox\" type=\"checkbox\" value=\"" + dr["iid"].ToString() + "\" />");
                    string pic_url = sp.DummyPaht + dr["pro_Thumbnail"].ToString();
                    if (dr["pro_Thumbnail"].ToString().IndexOf("http://") > -1)
                    {
                        pic_url = dr["pro_Thumbnail"].ToString();
                    }

                    table.AddCol("<span style='cursor:hand'  onMouseOut=\"hiddenPic();\" onMouseMove=\"showPic('" + pic_url + "');\">" + dr["pro_Name"].ToString() + "</span>");
                    table.AddCol("￥" + Convert.ToDouble(dr["pro_ShopPrice"].ToString()).ToString("f2"));
                    table.AddCol(string.Format("{0}{1}", dr["pro_Stock"].ToString(), dr["pro_Unit"].ToString()));
                    table.AddCol(string.Format("{0}<br>{1}", States(dr["pro_State"].ToString()), Designation(dr["pro_Designation"].ToString())));
                    table.AddCol(string.Format("<a algin=center href=product_detail.aspx?iid={0}&appkey={1}&appsecret={2} target='_blank'>商品描述</a> ", dr["iid"].ToString(), tb_appkey.Text, tb_appsecret.Text));
                    table.AddRow();
                }
                StringBuilder sb = new StringBuilder();
                p_page.Visible = true;
                string view = table.GetTable();
                this.Literal1.Text = view;
                State(pageindex,count);
            }
            else
            {
                p_page.Visible = false;
            }
           
            return dt.Rows.Count;
        }
        #region 状态
        /// <summary>
        /// 商品状态
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        protected string States(string str)
        {
            string reStr = string.Empty;
            string[] value = str.Split('|');
            for (int i = 0; i < value.Length; i++)
            {
                switch (i)
                {
                    case 0:
                        if (value[i].ToString() == "1")
                        {
                            reStr += "&nbsp;<span style='color:red'>推</span>";
                        }
                        else
                        {
                            reStr += "&nbsp;推";
                        }
                        break;
                    case 1:
                        if (value[i].ToString() == "1")
                        {
                            reStr += "&nbsp;<span style='color:red'>热</span>";
                        }
                        else
                        {
                            reStr += "&nbsp;热";
                        }
                        break;
                    case 2:
                        if (value[i].ToString() == "1")
                        {
                            reStr += "&nbsp;<span style='color:red'>特</span>";
                        }
                        else
                        {
                            reStr += "&nbsp;特";
                        }
                        break;
                    case 3:
                        if (value[i].ToString() == "1")
                        {
                            reStr += "&nbsp;<span style='color:red'>活</span>";
                        }
                        else
                        {
                            reStr += "&nbsp;活";
                        }
                        break;
                    case 4:
                        if (value[i].ToString() == "1")
                        {
                            reStr += "&nbsp;<span style='color:red'>新</span>";
                        }
                        else
                        {
                            reStr += "&nbsp;新";
                        }
                        break;
                    case 6:
                        if (value[i].ToString() == "1")
                        {
                            reStr += "&nbsp;<span style='color:red'>精</span>";
                        }
                        else
                        {
                            reStr += "&nbsp;精";
                        }
                        break;
                    case 5:
                        if (value[i].ToString() == "1")
                        {
                            reStr += "&nbsp;<span style='color:red'>首</span>";
                        }
                        else
                        {
                            reStr += "&nbsp;首";
                        }
                        break;
                }

            }
            return reStr;
        }
        #endregion
        #region 标示
        /// <summary>
        /// 商品提示
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        protected string Designation(string str)
        {
            string reStr = string.Empty;
            string[] value = str.Split('|');
            for (int i = 0; i < value.Length; i++)
            {
                switch (i)
                {
                    case 0:
                        if (value[i].ToString() == "1")
                        {
                            reStr += "&nbsp;<span style='color:red'>普</span>";
                        }
                        else
                        {
                            reStr += "&nbsp;普";
                        }
                        break;
                    case 1:
                        if (value[i].ToString() == "1")
                        {
                            reStr += "&nbsp;<span style='color:red'>团</span>";
                        }
                        else
                        {
                            reStr += "&nbsp;团";
                        }
                        break;
                    case 2:
                        if (value[i].ToString() == "1")
                        {
                            reStr += "&nbsp;<span style='color:red'>拍</span>";
                        }
                        else
                        {
                            reStr += "&nbsp;拍";
                        }
                        break;
                    case 3:
                        if (value[i].ToString() == "1")
                        {
                            reStr += "&nbsp;<span style='color:red'>点</span>";
                        }
                        else
                        {
                            reStr += "&nbsp;点";
                        }
                        break;
                    case 4:
                        if (value[i].ToString() == "1")
                        {
                            reStr += "&nbsp;<span style='color:red'>批</span>";
                        }
                        else
                        {
                            reStr += "&nbsp;批";
                        }
                        break;
                }
            }
            return reStr;
        }
        #endregion
        /// <summary>
        /// 获取分类
        /// </summary>
        /// <param name="strId"></param>
        /// <returns></returns>
        protected string ProductClassName(string strId)
        {
            string reStr = string.Empty;
            string str = "暂无归类";
            if (!string.IsNullOrEmpty(strId))
            {
                YXShop.BLL.Product.Productclass dll = new YXShop.BLL.Product.Productclass();
                DataTable dt = dll.GetMoreThanClassName(strId);
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    if (!string.IsNullOrEmpty(reStr))
                    {
                        reStr = reStr + "," + dt.Rows[i]["name"].ToString();
                    }
                    else
                    {
                        reStr = dt.Rows[i]["name"].ToString();
                    }
                }
                if (!string.IsNullOrEmpty(reStr))
                {
                    str = reStr;
                }
            }
            return str;
        }

        #region 导入数据
        /// <summary>
        /// 导入数据
        /// </summary>
        /// <param name="StrID"></param>
        private void insert(string StrID)
        {

            YXShop.BLL.Product.ProductInfo bll = new YXShop.BLL.Product.ProductInfo();
            YXShop.BLL.Product.ProductAlbum pabll = new YXShop.BLL.Product.ProductAlbum();
            YXShop.BLL.Product.ProductSparepart sbll = new YXShop.BLL.Product.ProductSparepart();
            YXShop.BLL.Product.ProductSpecification spebll = new YXShop.BLL.Product.ProductSpecification();
            YXShop.Model.Product.ProductInfo model = new YXShop.Model.Product.ProductInfo();
            ChangeHope.Common.UploadProcesedImages wm = new ChangeHope.Common.UploadProcesedImages();
            YXShop.Common.SysParameter sp = new YXShop.Common.SysParameter();
            StringBuilder sbr = new StringBuilder();
            #region 图片参数
            YXShop.Common.SysParameter sys = new YXShop.Common.SysParameter();

            string OriginalThumbnailSavePath = "yxuploadfile/product/originalthumbnail";
            string OriginalSavePath = "yxuploadfile/product/original";
            string ThumbnailSavePath = "yxuploadfile/product/thumbnail";
            int ThumbnailsHeight = sys.ThumbnailsHeight;
            int ThumbnailsWidth = sys.ThumbnailsWidth;
            int ImagesThumbnailsHeight = sys.ImagesThumbnailsHeight;
            int ImagesThumbnailsWidth = sys.ImagesThumbnailsWidth;

            string Original = string.Empty;
            string OriginalThumbnails = string.Empty;
            string ThumbnailsImage = string.Empty;
            #endregion
            DataTable dt = GetTable(StrID);
            if (dt.Rows.Count > 0)
            {
                int j = 0;
                int k=0;
                foreach (DataRow dr in dt.Rows)
                {
                    #region 加入商品表
                    string url = dr["pro_Original"].ToString().Trim();
                    string kz = System.IO.Path.GetExtension(url);
                    string type=string.Empty;
                    model.pro_Property = dr["pro_Property"].ToString();
                    model.pro_CID = this.w_d_pro_CID.Value;
                    model.pro_BrandID = Convert.ToInt32(dr["pro_BrandID"]);
                    model.pro_Name = dr["pro_Name"].ToString();              
                    model.pro_NO = dr["pro_NO"].ToString();
                    model.pro_KeyWord = dr["pro_Name"].ToString();
                    model.pro_ShopPrice = Convert.ToDecimal(dr["pro_ShopPrice"]);
                    model.pro_MarketPrice = Convert.ToDecimal(dr["pro_MarketPrice"]);
                    model.pro_RatingDiscount = dr["pro_RatingDiscount"].ToString();
                    model.pro_MetaDescription = dr["pro_MetaDescription"].ToString();
                    model.pro_EPoints = Convert.ToDecimal(dr["pro_EPoints"]);
                    model.pro_DonateIntegral = Convert.ToDecimal(dr["pro_DonateIntegral"]);
                    #region 上传原图
                    string filehead = ChangeHope.Common.DEncryptHelper.GetRandomNumber();
                    WebClient wc = new WebClient();
                    string filename = OriginalSavePath + "/" + filehead + kz;
                    wc.DownloadFile(url, Server.MapPath("~/" + filename));
                    Original = filename;
                    //原图缩略图
                    wm.SourceImagePath = Original;
                    wm.ThumbnailImagePath = OriginalThumbnailSavePath;
                    wm.ThumbnailImageWidth = ImagesThumbnailsWidth;
                    wm.ThumbnailImageHeight = ImagesThumbnailsHeight;
                    if (wm.ToThumbnailImage())
                    {
                        OriginalThumbnails = wm.FilePath;
                    }
                    #endregion
                    model.pro_Original = Original;
                    model.pro_Images = OriginalThumbnails;
                    #region 上传缩略图

                    wm.SourceImagePath = Original;
                    wm.ThumbnailImagePath = ThumbnailSavePath;
                    wm.ThumbnailImageWidth = ThumbnailsHeight;
                    wm.ThumbnailImageHeight = ThumbnailsWidth;
                    if (wm.ToThumbnailImage())
                    {
                        ThumbnailsImage = wm.FilePath;
                    }
                    #endregion
                    model.pro_Thumbnail = ThumbnailsImage;
                    model.pro_Synopsis = dr["pro_Synopsis"].ToString();
                    model.pro_Content = dr["pro_Content"].ToString();
                    model.pro_MetaKeywords = dr["pro_MetaKeywords"].ToString();
                    model.pro_MetaDescription = dr["pro_MetaDescription"].ToString();
                    model.pro_MetaTitle = dr["pro_MetaTitle"].ToString();
                    model.pro_Weight = Convert.ToDecimal(dr["pro_Weight"]);
                    model.pro_WeightUnit = 0;//默认为千克                
                    model.pro_Stock = Convert.ToInt32(dr["pro_Stock"]);
                    model.pro_Unit = dr["pro_Unit"].ToString();
                    model.pro_Alarm = Convert.ToInt32(dr["pro_Alarm"]);
                    model.pro_AuditCount = Convert.ToInt32(dr["pro_AuditCount"]);
                    model.pro_Audit = Convert.ToInt32(dr["pro_Audit"]);//默认为下架 因为批量导入的不是完整信息
                    model.pro_State = dr["pro_State"].ToString();
                    model.pro_Designation = dr["pro_Designation"].ToString();
                    model.pro_RelatingArtID = dr["pro_RelatingArtID"].ToString();
                    model.pro_RelatingproID = dr["pro_RelatingproID"].ToString();
                    model.pro_CreateTime = Convert.ToDateTime(dr["pro_CreateTime"]);
                    model.pro_UpdateTime = Convert.ToDateTime(dr["pro_UpdateTime"]);
                    model.pro_OnClicks = Convert.ToInt32(dr["pro_OnClicks"]);
                    model.pro_IsAllowComment = Convert.ToInt32(dr["pro_IsAllowComment"]);
                    model.pro_SaleNum = Convert.ToInt32(dr["pro_SaleNum"]);
                    model.pro_CostPrice = Convert.ToDecimal(dr["pro_CostPrice"]);
                    model.pro_AutoUp = Convert.ToDateTime(dr["pro_AutoUp"]);
                    model.pro_AutoDown = Convert.ToDateTime(dr["pro_AutoDown"]);

                    if (dr["pro_IsAuto"].ToString() == "onsale")
                    {
                        model.pro_IsAuto = 1;
                    }
                    else
                    {
                        model.pro_IsAuto = 0;
                    }
                    model.pro_SaleType = 0;
                    model.pro_IntegralPrice = Convert.ToDecimal(dr["pro_IntegralPrice"]);
                    if (this.w_l_pro_Area.Value != string.Empty && this.w_l_pro_Area.Value != "")
                    {
                        model.pro_Area = this.w_l_pro_Area.Value;
                    }
                    else
                    {
                        model.pro_Area = string.Empty;
                    }
                    model.pro_PutoutID = Convert.ToInt32(dr["pro_PutoutID"]);
                    model.pro_PutoutType = Convert.ToInt32(dr["pro_PutoutType"]);
                    model.pro_Templates = dr["pro_Templates"].ToString();           
                    int a = -1;
                    if (dr["pro_NO"].ToString() != "")
                    {
                        DataTable dtno = bll.DTGetListWhere("and pro_NO='" + dr["pro_NO"].ToString() + "'");
                        if (dtno.Rows.Count == 0)
                        { 
                            type="add";
                          a = bll.Add(model); 
                            
                            j++;
                        }
                        else if (dtno.Rows.Count == 1)
                        {
                             type="update";
                            model.pro_ID = Convert.ToInt32(dtno.Rows[0]["pro_ID"]);
                            if(bll.Update(model)>0)
                            {
                              a=model.pro_ID;
                              sbr.Append("商品名称:" + model.pro_Name + "，导入修改成功！<br>");
                              k++;
                            }
                            else
                            {
                                sbr.Append("商品名称:" + model.pro_Name + "'，导入修改失败！<br>");
                            }
                        }

                    }
                    string alb = dr["imgs"].ToString();
                    if (alb != "")
                    {
                        Album(alb,a,type);
                    }
                    #endregion   
                }
                sbr.Append("一共" + dt.Rows.Count + "条数据，导入成功" + j.ToString() + "条，修改成功" + k.ToString() + "条。<br>");
                this.ltlMsg.Text = sbr.ToString();
                this.pnlMsg.Visible = true;
                this.pnlMsg.CssClass = "actionOk";
            }

        }
        #endregion
        #region 商品相册
        /// <summary>
        /// 上传商品相册图
        /// </summary>
        /// <param name="al"></param>
        /// <param name="id"></param>
        protected void Album(string al, int id,string type)
        {

            string[] a = al.Split(',');
            WebClient wc = new WebClient();

            YXShop.BLL.Product.ProductAlbum pabll = new YXShop.BLL.Product.ProductAlbum();
            YXShop.Common.SysParameter sys = new YXShop.Common.SysParameter();
            int ImagesThumbnailsHeight = sys.ImagesThumbnailsHeight;
            int ImagesThumbnailsWidth = sys.ImagesThumbnailsWidth;
            string AlbumThumbnailSave = "yxuploadfile/product/albumthumbnail";
            string AlbumOriginalSave = "yxuploadfile/product/albumoriginal";
            string AlbumThumbnail = string.Empty;
            string AlbumOriginal = string.Empty;
            if(type!="add")
            {
                pabll.DelAll(id.ToString());
            }
           

            for (int i = 0; i < a.Length; i++)
            {
                if (a[i] != "")
                {
                    YXShop.Model.Product.ProductAlbum pa = new YXShop.Model.Product.ProductAlbum();
                    pa.Productid = id;
                    pa.Description = string.Empty;
                    string url = a[i].ToString();
                    string kz = System.IO.Path.GetExtension(url);
                    string filehead = ChangeHope.Common.DEncryptHelper.GetRandomNumber();
                    string filename = AlbumOriginalSave + "/" + filehead + kz;
                    wc.DownloadFile(url, Server.MapPath("~/" + filename));
                    AlbumOriginal = filename;

                    ChangeHope.Common.UploadProcesedImages wm = new ChangeHope.Common.UploadProcesedImages();
                    wm.SourceImagePath = filename;
                    wm.ThumbnailImagePath = AlbumThumbnailSave;
                    wm.ThumbnailImageWidth = ImagesThumbnailsWidth;
                    wm.ThumbnailImageHeight = ImagesThumbnailsHeight;
                    if (wm.ToThumbnailImage())
                    {
                        AlbumThumbnail = wm.FilePath;
                    }
                    pa.OriginalAddress = AlbumOriginal;
                    pa.ThumbnailAddress = AlbumThumbnail;
                    if (AlbumThumbnail != string.Empty)
                    {
                        pabll.Add(pa);
                    }
                }
            }
        }
        #endregion
        /// <summary>
        /// 导入操作
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void butImport_Click(object sender, EventArgs e)
        {
            if (this.w_d_pro_CID.Value == "" || this.w_d_pro_CID.Value == string.Empty)
            {
                this.ltlMsg.Text = "请选择导入的所属分类！";
                this.pnlMsg.Visible = true;
                this.pnlMsg.CssClass = "actionErr";
                return;
            }
            else
            {

                string id = ChangeHope.WebPage.PageRequest.GetFormString("cBox");
                if (id != "")
                {
                    try
                    {
                        YXShop.Common.PromptInfo.Popedom("001006006", "对不起，您没有权限进行批量导入");
                        insert(id);
                    }
                    catch (Exception ex)
                    {
                        this.ltlMsg.Text = ex.Message;
                        this.pnlMsg.Visible = true;
                        this.pnlMsg.CssClass = "actionErr";
                    }
                }
                else
                {
                    this.ltlMsg.Text ="请选选择选项！";
                    this.pnlMsg.Visible = true;
                    this.pnlMsg.CssClass = "actionErr";
                }

            }
        }

        /// <summary>
        /// 末页
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void butImport3_Click(object sender, EventArgs e)
        {
            int pageindex = Convert.ToInt32(lb_totalpage.Text);
            GetList(tb_appkey.Text, tb_appsecret.Text, pageindex);
            pl_news.Visible = false;
            p_bottom.Visible = true;
        }

        /// <summary>
        /// 上一页
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void butImport2_Click(object sender, EventArgs e)
        {
            int pageindex=-1;
            int now = Convert.ToInt32(lb_nowpage.Text);
            if (now > 1)
            {
                pageindex = now - 1;
                GetList(tb_appkey.Text, tb_appsecret.Text, pageindex);
                pl_news.Visible = false;
                p_bottom.Visible = true;
            }
            
        }

        /// <summary>
        /// 下一页
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void butImport1_Click(object sender, EventArgs e)
        {
            int pageindex=-1;
            int now = Convert.ToInt32(lb_nowpage.Text);
            int totalpage=Convert.ToInt32(lb_totalpage.Text);
            if (now <totalpage)
            {
                pageindex = now + 1;
                GetList(tb_appkey.Text, tb_appsecret.Text, pageindex);
                pl_news.Visible = false;
                p_bottom.Visible = true;
            }
        }
        /// <summary>
        /// 首页
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void butImport0_Click(object sender, EventArgs e)
        {
           int pageindex = 1;
            GetList(tb_appkey.Text, tb_appsecret.Text, pageindex);
            pl_news.Visible = false;
            p_bottom.Visible = true;
        }
        protected void State(int pageindex,long count)
        {
            long pagecount;

            long a = count % 20;
            if (a == 0)
            {
                pagecount = count / 20;
            }
            else
            {
                pagecount = count / 20 + 1;
            }

            if (pagecount <= 1)
            {//即是第1页页是最后一页
                butImport0.Enabled = false;
                butImport1.Enabled = false;
                butImport2.Enabled = false;
                butImport3.Enabled = false;
            }
            else
            {
                if (pageindex == 1)
                {//第一页
                    butImport0.Enabled = false;
                    butImport1.Enabled = true;
                    butImport2.Enabled = false;
                    butImport3.Enabled = true;
                }

                else if (pageindex == pagecount)
                {//最后一页
                    butImport0.Enabled = true;
                    butImport1.Enabled = false;
                    butImport2.Enabled = true;
                    butImport3.Enabled = false;
                }
                else
                {
                   //中间页
                        butImport0.Enabled = true;
                        butImport1.Enabled = true;
                        butImport2.Enabled = true;
                        butImport3.Enabled = true;             
                }

            }

            lb_totalcount.Text = count.ToString();
            lb_totalpage.Text = pagecount.ToString();
            lb_nowpage.Text = pageindex.ToString();
        }


    }
}
